<%@page import="Filter.carlist"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.ArrayList"%>
<%@page import="Filter.DAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% double total = 0.0; int x ;%>
<%
    String sql="select * from product";
    DAO db = new DAO();
    ArrayList<HashMap> rslist= db.query(sql, new String[]{}); 
    ArrayList<HashMap> carlist=(ArrayList<HashMap>)session.getAttribute("carlist");
    HashMap carmap = null;
    
    //刪除功能
    /*String rid=request.getParameter("removeid");
    out.println(rid);
    if(rid!=null)
     {   
        out.println(rid);
        carlist.remove(Integer.parseInt(rid));
     }
    */
    
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <style>
            #table {border-width:2px; border: #000; border-style: double;}
            tr {padding:10px;}
            td {padding:10px;}
            
        </style>        
        
    </head>
    <body>
        <div>     
            <form action="cashCheckLogin" method="post">
               <tr> <h1>結帳頁面</h1>   <br></tr>
               <tr>姓名:<input type="text" name="user"><br><br></tr>
               <tr>地址:<input type="text" name="address"><br><br></tr>
               <tr>運送方式:<select name="deliver"></tr>
                   <option value="null">--請選擇--</option>
                   <option value="dog">黑狗快遞</option>
                   <option value="pig">黑豬快遞</option>
                   <option value="cat">黑貓快遞</option>
               </select>
               <!-- <tr>訂單編號:<br><br></tr> -->
               <br><br>
               <table id="table">
                <caption style="font-weight: bold">明細表</caption>
              <th colspan="2" id="table"> 商品</th><th id="table">價錢</th>
              <% if(!carlist.isEmpty()){
                  for(int i=0 ; i<carlist.size() ; i++){                   
                  carmap = carlist.get(i);                  
                  total = total+Double.parseDouble((String)carmap.get("product_price"));
                  out.println("<tr><td><img src='"+carmap.get("img_url")
                                +"' style='width:160px;height:120px;'/> </td><td>"
                                +carmap.get("product_name")+
                              "</td><td align='right'>"
                                +carmap.get("product_price")
                                +"</td></tr></th>");}
                  /* 刪除功能按鈕
                  out.println(i+"<input type=button value='刪除' onclick='del("+i+")'");*/
                  
                  out.println("<tr><td></td><td></td><td>"+
                            "<p align='right'>總金額:" +total
                                + "</td></tr>");
            }else out.print("尚未選購商品!<br><br>");
           %>   
              
           </table>
           <!--  刪除功能放棄 
           <form action="<%--= response.encodeURL("cash.jsp")--%>" method="post" id="delf" name="delf">
               <input type="hidden" name="removeid" id='rid'>
           </form>  -->
                <tr>                    
                    <a href="cash_cancel.jsp"><input type="submit" value="結帳"  style="margin:50px 0 0 280px; width: 80px; height: 35px;" onsubmit="<%carlist.clear();%>"/> </a> 
                    <a href="cash_cancel.jsp"><input type="button" value="取消"  style="margin:50px 0 0 30px; width: 80px; height: 35px;"/></a>
                    <a href="ProductList.jsp"><input type="button" value="再去買"  style="margin:50px 0 0 30px; width: 80px; height: 35px;"/></a>
                </tr>   
           </form>
        </div> 
           
              
           <script type="text/javascript">              
               
            /* 刪除功能 script    
            function del(id)
                {   alert("11");                
                    if (confirm("當真不買?!"))
                    {  
                       alert("You Suck !!");                         
                       document.getElementById("rid").value(id);                       
                       alert(id);                         
                       alert(document.getElementById("delf"));                       
                       document.getElementById("delf").submit();                       
                       alert("You Suck 3!");  
                       //window.location.reload(r);             
                    }
                    else { alert("I Love U !"); }
                }*/ 
        </script>      
           
    </body>
</html>
